<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        li {
            min-height: 50px;
            list-style: none;
            line-height: 50px;
            background-color: pink;
            margin: 10px 0;
        }

        li p:first-child {
            padding-top: 40px;
        }

        * {
            margin: 0;
            padding: 0;
        }
    </style>
</head>

<body>
    <ul> </ul>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script>
        let ul = document.querySelector("ul");
        $.ajax({
            url: 'http://apis.juhe.cn/goodbook/catalog',
            data: {
                key: '0f38468a2a3dd088f98c6c2fefc6cacc'
            },
            dataType: 'jsonp',
            success(res) {
                let str = '';
                console.log(res);
                res.result.forEach(item => {
                    str += `<li id="${item.id}">${item.catalog}</li>`
                })
                ul.innerHTML = str;
            }
        })
        ul.onclick = function (ap) {
            let target = ap.target;
            let id = target.id;
            $.ajax({
                url: 'http://apis.juhe.cn/goodbook/query',
                data: {
                    key: '0f38468a2a3dd088f98c6c2fefc6cacc',
                    catalog_id: id,
                    pn: 1,
                    rn: 10,
                },
                dataType: 'jsonp',
                success(res) {
                    let str = '';
                    res.result.data.forEach(item => {
                        str += `<p>${item.title}</p>`
                    })
                    target.innerHTML += str;
                }
            })
        }
    </script>
</body>

</html>